package com.google.code.cisx.model.project;

import com.google.code.cisx.model.CommonUpdatableModelEntity;

import java.util.Map;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * Configures one method for notifying users/developers when a build breaks.
 * <p>
 * TODO: Review this to use discriminators for different Notifier extensions.
 * 
 * @version $Id: ProjectNotifier.java 102 2008-01-05 22:07:30Z rahul.thakur.xdev
 *          $
 */
@Entity
@Table(name = "PROJECT_NOTIFIER")
public class ProjectNotifier extends CommonUpdatableModelEntity {

	/**
	 * Field type
	 * <p>
	 * TODO: This is a candidate for enum type.
	 */
	@Basic
	@Column(name = "GROUP_ID")
	private String type = "mail";

	/**
	 * Field from
	 */
	@Basic
	@Column(name = "NOTIFIER_ORIGIN", nullable = false)
	private int from = 0;

	/**
	 * Field enabled
	 */
	@Basic
	@Column(name = "FLG_ENABLED", nullable = false)
	private boolean enabled = true;

	/**
	 * Field recipientType
	 */
	@Basic
	@Column(name = "RECIPIENT_TYPE", nullable = false)
	private int recipientType = 0;

	/**
	 * Field sendOnSuccess
	 */
	@Basic
	@Column(name = "FLG_SEND_ON_SUCCESS", nullable = false)
	private boolean sendOnSuccess = true;

	/**
	 * Field sendOnFailure
	 */
	@Basic
	@Column(name = "FLG_SEND_ON_FAILURE", nullable = false)
	private boolean sendOnFailure = true;

	/**
	 * Field sendOnError
	 */
	@Basic
	@Column(name = "FLG_SEND_ON_ERROR", nullable = false)
	private boolean sendOnError = true;

	/**
	 * Field sendOnWarning
	 */
	@Basic
	@Column(name = "FLG_SEND_ON_WARNING", nullable = false)
	private boolean sendOnWarning = true;

	/**
	 * Field configuration.
	 * <p>
	 * TODO: Map!
	 */
	@Transient
	private Map configuration;

	/**
	 * TODO: Map! Enum?
	 */
	public static final int FROM_PROJECT = 1;

	/**
	 * TODO: Map! Enum?
	 */
	public static final int FROM_USER = 2;

	/**
	 * Method toString
	 */
	public java.lang.String toString() {
		StringBuffer buf = new StringBuffer();
		buf.append("id = '");
		buf.append(getId() + "'");
		return buf.toString();
	} // -- java.lang.String toString()

	public boolean isFromProject() {
		return from == FROM_PROJECT;
	}

	public boolean isFromUser() {
		return from == FROM_USER;
	}

	/**
	 * @return the type
	 */
	public String getType() {
		return type;
	}

	/**
	 * @param type
	 *          the type to set
	 */
	public void setType(String type) {
		this.type = type;
	}

	/**
	 * @return the from
	 */
	public int getFrom() {
		return from;
	}

	/**
	 * @param from
	 *          the from to set
	 */
	public void setFrom(int from) {
		this.from = from;
	}

	/**
	 * @return the enabled
	 */
	public boolean isEnabled() {
		return enabled;
	}

	/**
	 * @param enabled
	 *          the enabled to set
	 */
	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	/**
	 * @return the recipientType
	 */
	public int getRecipientType() {
		return recipientType;
	}

	/**
	 * @param recipientType
	 *          the recipientType to set
	 */
	public void setRecipientType(int recipientType) {
		this.recipientType = recipientType;
	}

	/**
	 * @return the sendOnSuccess
	 */
	public boolean isSendOnSuccess() {
		return sendOnSuccess;
	}

	/**
	 * @param sendOnSuccess
	 *          the sendOnSuccess to set
	 */
	public void setSendOnSuccess(boolean sendOnSuccess) {
		this.sendOnSuccess = sendOnSuccess;
	}

	/**
	 * @return the sendOnFailure
	 */
	public boolean isSendOnFailure() {
		return sendOnFailure;
	}

	/**
	 * @param sendOnFailure
	 *          the sendOnFailure to set
	 */
	public void setSendOnFailure(boolean sendOnFailure) {
		this.sendOnFailure = sendOnFailure;
	}

	/**
	 * @return the sendOnError
	 */
	public boolean isSendOnError() {
		return sendOnError;
	}

	/**
	 * @param sendOnError
	 *          the sendOnError to set
	 */
	public void setSendOnError(boolean sendOnError) {
		this.sendOnError = sendOnError;
	}

	/**
	 * @return the sendOnWarning
	 */
	public boolean isSendOnWarning() {
		return sendOnWarning;
	}

	/**
	 * @param sendOnWarning
	 *          the sendOnWarning to set
	 */
	public void setSendOnWarning(boolean sendOnWarning) {
		this.sendOnWarning = sendOnWarning;
	}

	/**
	 * @return the configuration
	 */
	public Map getConfiguration() {
		return configuration;
	}

	/**
	 * @param configuration
	 *          the configuration to set
	 */
	public void setConfiguration(Map configuration) {
		this.configuration = configuration;
	}

}
